package net.tycmc.cty.ctyms.web.Dao;

import java.util.List;
import java.util.Map;

import net.tycmc.bulb.common.dao.IBaseDAO;
import net.tycmc.bulb.common.util.DateUtil;
import net.tycmc.cty.ctyms.timejob.common.MyBaseDAO;
import net.tycmc.cty.ctyms.timejob.common.MyConnectDSDAO;
import net.tycmc.cty.ctyms.timejob.common.MyConnectDSTransDAO;

public class DataMonitorListDao {
	private IBaseDAO baseDAO;
	private MyBaseDAO mbd;
	public MyBaseDAO getMbd() {
		return mbd;
	}

	public void setMbd(MyBaseDAO mbd) {
		this.mbd = mbd;
	}

	public IBaseDAO getBaseDAO() {
		return baseDAO;
	}

	public void setBaseDAO(IBaseDAO baseDAO) {
		this.baseDAO = baseDAO;
	}
	
	/**
	 * 获取过去三天各个监控的数据列表
	 * @return
	 */
	public List<Map<String,Object>>getDataOfHistory(String beginTime,String endTime){
		String CollectParamsql="select count(*)cnt,type=1,convert(varchar(10),Vncp_msgTime,120) stateTime from VclNoCollectParam where Vncp_msgTime<='"+endTime+"' and Vncp_msgTime>='"+beginTime+"' group by Vncp_msgTime";//参数采集sql
		String VclCollectFresql="select count(*)cnt,type=2,convert(varchar(10),Vclf_msgTime,120) stateTime from VclCollectFre where Vclf_msgTime<='"+endTime+"' and Vclf_msgTime>='"+beginTime+"' group by Vclf_msgTime";//采集频率sql
		String DB2OfVclsql="select count(*)cnt,type=3,convert(varchar(10),DB2OV_msgTime,120) stateTime from DB2OfVcl where DB2OV_msgTime<='"+endTime+"' and DB2OV_msgTime>='"+beginTime+"' group by DB2OV_msgTime";//参数采集sql
		String DCFZOfVclsql="select count(*)cnt,type=4,convert(varchar(10),DCFZOV_msgTime,120) stateTime from DCFZOfVcl where DCFZOV_msgTime<='"+endTime+"' and DCFZOV_msgTime>='"+beginTime+"' group by DCFZOV_msgTime";//参数采集sql
		String LoadRateOfVclsql="select count(*)cnt,type=5,convert(varchar(10),Lrov_msgTime,120) stateTime from LoadRateOfVcl where Lrov_msgTime<='"+endTime+"' and Lrov_msgTime>='"+beginTime+"' group by Lrov_msgTime";//参数采集sql
		String RunKmOfVclsql="select count(*)cnt,type=6,convert(varchar(10),RKOV_msgTime,120) stateTime from RunKmOfVcl where RKOV_msgTime<='"+endTime+"' and RKOV_msgTime>='"+beginTime+"' group by RKOV_msgTime";//参数采集sql
		String resultSql=CollectParamsql+" union all "+VclCollectFresql+" union all "+DB2OfVclsql+" union all "+DCFZOfVclsql+" union all "+LoadRateOfVclsql+" union all "+RunKmOfVclsql;
		return baseDAO.execQuery(resultSql,new Object[]{});
	}
	/**
	 * 更新标记表、并且清空昨日表
	 * @return
	 */
	public int updateFlagTable(){
		String sql="update ParamCollectFlag set pcf_FinalmsgTime=null ";
		sql+=" delete from VclNoCollectParam where Vncp_msgTime ='"+DateUtil.addDay(-1)+"'";
		sql+=" delete from VclCollectFre where Vclf_msgTime ='"+DateUtil.addDay(-1)+"'";
		sql+=" delete from DB2OfVcl where DB2OV_msgTime ='"+DateUtil.addDay(-1)+"'";
		sql+=" delete from DCFZOfVcl where DCFZOV_msgTime ='"+DateUtil.addDay(-1)+"'";
		sql+=" delete from LoadRateOfVcl where Lrov_msgTime ='"+DateUtil.addDay(-1)+"'";
		sql+=" delete from RunKmOfVcl where RKOV_msgTime ='"+DateUtil.addDay(-1)+"'";
		MyConnectDSDAO conn=new MyConnectDSDAO(true);
		conn.execUpdate(sql,new Object[]{});//修改备份库
		return baseDAO.execUpdate(sql,new Object[]{});
	}
}
